<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
    protected $table='permission';
    protected $guarded=[];
    public $timestamps=false;
    //保存新建用户
    public static function checkPermission($request){
        $data['name']=$request->name;
        $data['route']=$request->route;
        $data['description']=$request->description;
        $newPermission=Permission::create($data);
        if($newPermission){
            return redirect()->back()->with('status','小主！添加成功！');
        }else{
            $request->session()->flash('name', "$request->name");
            $request->session()->flash('route', "$request->route");
            $request->session()->flash('description', "$request->description");
            return redirect()->back()->with('status','小主！添加失败!');
        }

    }

    /*
     * 编辑用户
     * */
    public static function updatePermission($request){
        $data['name']=$request->name;
        $data['route']=$request->route;
        $data['description']=$request->description;


        $updatePermission=Permission::where('id',$request->permissionId)->update($data);
        if($updatePermission){
            return  back()->with('status','修改成功');
        }else{
            return  back()->with('status','权限未做任何修改');
        }
    }
}
